package com.tsingteng.cosfun.ui.search;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.bean.SearchUserResp;
import com.tsingteng.cosfun.common.Constant;
import com.tsingteng.cosfun.ui.mine.HomeMineFragment;
import com.tsingteng.cosfun.ui.mine.TerminalActivity;
import com.tsingteng.cosfun.utils.ImageUtils;
import com.tsingteng.cosfun.utils.LogonUtils;
import com.tsingteng.cosfun.utils.StringUtils;
import com.tsingteng.cosfun.utils.ToastUtils;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class RecommentAdapter extends BaseQuickAdapter<SearchUserResp,BaseViewHolder> {
    private Context mContext;
    private SearchFanListener listener;
    private final int FOOTERLAYOUT = 100;//加载更多
    private int viewType = 0;
    public RecommentAdapter(Context context,SearchFanListener mListener) {
        super(R.layout.item_fans_search);
        this.mContext = context;
        this.listener = mListener;
    }

//    @Override
//    public int getItemViewType(int position) {
//        if (getItemCount() > 0 && position == getItemCount() - 1) {
//            viewType = FOOTERLAYOUT;
//            return FOOTERLAYOUT;
//        } else {
//            viewType = 0;
//            return 0;
//        }
//    }

//    @Override
//    public int getItemCount() {
//        if (getData().size()==0) {
//            return 0;
//        }
//        return getData().size()+1;
//
//    }
    @Override
    protected void convert(BaseViewHolder helper, SearchUserResp item) {
        RelativeLayout mRlItemFanTitle = helper.getView(R.id.rl_item_fan_title);
        TextView mFooterNomoreTv = helper.getView(R.id.footer_nomore_tv);
//        if (viewType == FOOTERLAYOUT){
//            mRlItemFanTitle.setVisibility(View.GONE);
//            mFooterNomoreTv.setVisibility(View.VISIBLE);
//            return;
//        }
        mFooterNomoreTv.setVisibility(View.GONE);
        mRlItemFanTitle.setVisibility(View.VISIBLE);
        CircleImageView mIvFansHeader = helper.getView(R.id.iv_fans_header);
        TextView mTvFansTitle = helper.getView(R.id.tv_fans_title);
        TextView mTvFansId = helper.getView(R.id.tv_fans_id);
        TextView mFanNumTv = helper.getView(R.id.fan_num_tv);
        TextView mFanWorkTv = helper.getView(R.id.fan_work_tv);
        TextView mTvFansFollow = helper.getView(R.id.tv_fans_follow);
        mTvFansTitle.setText(item.getProfileName());
        String fans = StringUtils.formatZanCount(Integer.parseInt(item.getNumberOfFans()));
        String fan = fans+mContext.getResources().getString(R.string.fans);
        String work = item.getNumberOfWorks()+mContext.getResources().getString(R.string.commonet);
        String  mId = mContext.getResources().getString(R.string.profile_id)+item.getProfileId();
        mFanNumTv.setText(fan);
        mFanWorkTv.setText(work);
        mTvFansId.setText(mId);
        ImageUtils.LoadImage(mContext, item.getProfileAvatar(), mIvFansHeader);
        if (1 == item.getIsAttention()){
            mTvFansFollow.setText(mContext.getResources().getString(R.string.focused));
            mTvFansFollow.setTextColor(mContext.getResources().getColor(R.color.color_found));
            mTvFansFollow.setBackground(mContext.getResources().getDrawable(R.drawable.shape_bg_focused));
        }else if (0 == item.getIsAttention()){
            mTvFansFollow.setText(mContext.getResources().getString(R.string.focus));
            mTvFansFollow.setTextColor(mContext.getResources().getColor(R.color.black));
            mTvFansFollow.setBackground(mContext.getResources().getDrawable(R.drawable.shape_logout));
        }else if (2 == item.getIsAttention()){
            mTvFansFollow.setText(mContext.getResources().getString(R.string.focus_each));
            mTvFansFollow.setTextColor(mContext.getResources().getColor(R.color.black));
            mTvFansFollow.setBackground(mContext.getResources().getDrawable(R.drawable.shape_logout));
        }
        mTvFansFollow.setOnClickListener(view -> {
            if (item.getProfileId()== LogonUtils.getProFildId()){
                ToastUtils.showToast(mContext.getResources().getString(R.string.cannot_us));
            }else {
                listener.searchFanListener(helper.getAdapterPosition(), item);
            }
        });
        mIvFansHeader.setOnClickListener(view -> {
            listener.clickImages(helper.getAdapterPosition(), item);
        });
    }

    interface SearchFanListener{
        void searchFanListener(int position,SearchUserResp listResp);
        void clickImages(int position,SearchUserResp listResp);
    }
}
